Desktop/Copy of GPS_TRACE/SRC/NMEA0183Parser.c

Go to the documentation of this file.
00001 #include <string.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <avr/interrupt.h>
00005 #include <avr/signal.h>
00006 #include "NMEA0183Parser.h"
00007 #include "lcd.h"
00008 #include "RS232.h"
00009 #include "status.h"
00010 
00011 void initNMEA(){
00012         state=0;
00013         CMD_count=0;
00014         COMMAND_count=0;
00015         test=0;
00016         fora=0;
00017 }
00018 
00019 void NMEAFeedBuffer (char pdata)
00020 {
00021         data=pdata;
00022         ProcessNMEA();
00023 }
00024 
00025 int ProcessCMD()
00026 {
00027 
00028         if (CMD_count < 4)
00029         {
00030                 CMD[CMD_count]=data;
00031                 CMD_count++;
00032                 return 0;
00033         }
00034         if (CMD_count == 4)
00035         {
00036                 CMD[CMD_count]=data;
00037                 CMD_count=0;
00038                 return 1;
00039         }
00040 
00041         return -1;
00042 }
00043 
00044  
00045 void ProcessNMEA(){
00046 
00047         switch (state)
00048         {
00049                 case 0: 
00050                         if (data=='$')
00051                         {
00052                                 state=1;
00053                         }
00054                 break;
00055 
00056                 case 1:
00057                         if (ProcessCMD()==1)
00058                         { 
00059                                 state=2;
00060                         }
00061                 break;
00062                 case 2:
00063                         if (CMD[4]=='A'&&CMD[3]=='G')
00064                         {
00065                                 state=3;
00066                         }
00067                         else
00068                         {
00069                                 state=0;
00070                         }
00071                 
00072                 break;
00073                 
00074                 case 3:
00075                         if (data!='$')
00076                         {       
00077                                 COMMAND[COMMAND_count]=data; // niet goed gevuld ofzo ? 
00078                             COMMAND_count++;
00079                         }
00080                         if (data=='$')
00081                         {
00082                                 
00083                         cli(); //interrupts uit
00084                                 UpdateStatus();
00085                                 COMMAND_count=0;
00086                                 fora=0;
00087                                 state = 1;
00088                         sei(); //interrupts aan
00089                         }
00090                         
00091                 break;
00092                 default : state=0;
00093         }
00094 }
00095 
00096 void GetField (int fieldnumber, int offset)
00097 {
00098                 int fieldcount=0; //veldpositie
00099                 int s=0; //for-loop var
00100                 for (; s < COMMAND_count; s++)
00101                 {
00102                         if (COMMAND[s]==',')
00103                         {
00104                                 fieldcount++;
00105                                 if (fieldcount==fieldnumber)
00106                                 {
00107                                         int t=0;//for-loop var
00108                                         for (; t < offset; t++)
00109                                         {
00110                                                 result[t]=COMMAND[t+s+1];
00111                                         }
00112                                 }
00113                         }
00114                 }
00115 }
00116 
00117 void UpdateStatus()
00118 {
00119         //SetFixState
00120         GetField (5,2);
00121         setFixstate(result[0]);
00122         //Set NS indicator 
00123         GetField (2,2);
00124         setNS_indicator(result[0]);
00125         //Set EW indicator 
00126         GetField (4,2);
00127         setEW_indicator(result[0]);
00128         //Set Latitude 
00129         GetField (1,10);
00130         setLatitude(result);
00131         FormatLatitude();
00132         showLongitudeFormatted();
00133         GetField (3,10);
00134         setLongitude(result);
00135         FormatLongitude();
00136         showLatitudeFormatted();
00137         //This one is to send sms with position 
00138         if (test==0)
00139         {
00140 //              ReportPosition();
00141                 test=1;
00142         }
00143 
00144 }
00145 
00146 
00147 
00148 
00149 
00150 

Generated on Fri Aug 17 13:50:54 2007 for GPS TRACE by  doxygen 1.5.3